package com.turboconnard.menu;

import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.SubMenu;

public class MainMenu {
	private static MainMenu _instance;
	public AndroidMenu currentMenu;
	public int uniqueId;
	
	//private Menu _androidMenu;
	public MainMenu(){
		uniqueId = 0;
		//_androidMenu = pMenu;
		_instance = this;		
	}
	public static MainMenu getInstance(){
		return _instance;		
	}
	public void add(String pMenu){
		//_androidMenu.add(0,1,0,pMenu);
	}
	public void open(Menu pMenu){
		for (AndroidMenuItem ami : currentMenu.items) {
			if(ami.subMenus.size()>0){
				SubMenu sm = pMenu.addSubMenu(0,ami.id,0,ami.label);
				for (AndroidMenuItem am : ami.subMenus) {
					sm.add(0, am.id, 0, am.label);
				}
			}else {
				MenuItem a = pMenu.add(0,ami.id,0,ami.label);
				if(ami.icon != -1) a.setIcon(ami.icon );
			}
		}
	}
	public boolean select(MenuItem item) {
		for (AndroidMenuItem ami : currentMenu.items) {
			if(ami.subMenus.size()>0){
				//Log.d("MENU","SOUS MENU !");
				for (AndroidMenuItem am : ami.subMenus) {
					if(item.getItemId() == am.id) am.select();
				}
			}else{
				if(item.getItemId() == ami.id) ami.select();
			}
		}
		// TODO Auto-generated method stub
		return false;
	}
	public int getUniqueId() {
		return uniqueId++;
	}
}